package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
@Configuration
public class OrderCanelMqConfig {
    @Bean
    public Queue delayQeue1(){
        return new Queue(MqConst.QUEUE_ORDER_CANCEL,true,false,false);
    }

    //    定义交换机
    @Bean
    public CustomExchange delayExchange(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,map);
    }

    //    绑定队列
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(delayQeue1()).to(delayExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}

